<?php
namespace Admin\Model;
use Think\Model;
class FiledModel extends Model{
	protected $tableName="filed";
	protected $patchValidate = true;
	//添加字段
	public function d(){
		if($this->create()){
			$mid=I('mid');
			$db=S('m');
			$f_type=I('f_type');
			$field=I('f_fild');
			foreach ($db as $k => $v) {
				if(in_array($mid, $v)){
					$m_table_name=$v['m_table_name'];
				}	
			}
			$_POST['t_name']=$m_table_name;
			$addFiled=$this->add($_POST);
			if($addFiled){
				$fied=M('type')->where("f_type="."'$f_type'")->getField('fied');
				$sql="AlTER TABLE d_$m_table_name add $field $fied";
				M()->query($sql);
				return $this->updateCache();

				}		
		}else{
			return false;
		}
	
}
	

	// 缓存
	public function updateCache(){
		S('f',null);
		$FiledData = $this->select();
		if(empty($FiledData)){
			return true;
		}
		$cache=S('f',$FiledData);
		if($cache){
			return true;
		}else{
			return false;
		}

	}



}